"""
处理yaml文件的读取与输入以及清空
"""

import yaml

# filename 需要传入相对路径或者绝对路径，不能只传入文件名

# 写入文件
def write_yaml(filename, data):
    with open(filename, 'a+', encoding='utf-8') as f:
        yaml.safe_dump(data, stream=f)


# 读取文件
def read_yaml(filename):
    with open(filename, 'r', encoding='utf-8') as f:
        return yaml.safe_load(f)


# 清空文件
def clear(filename):
    with open(filename, 'w', encoding='utf-8') as f:
        f.truncate()